package com.zjl.aop.advice;

import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Auther: zhuangjl
 * @Date: 2021/12/14 18:15
 */
@Configuration
public class AdviceProxyConfig {

    @Bean("debugInterceptor")
    public DebugInterceptor debugInterceptor(){

        return new DebugInterceptor();
    }

    @Bean("personTarget")
    public PersonImpl personTarget(){

        return new PersonImpl();
    }

    @Bean("myAdvisor")
    public DefaultPointcutAdvisor myAdvisor(){

        return new DefaultPointcutAdvisor();
    }
    @Bean("person")
    public ProxyFactoryBean  person() throws ClassNotFoundException {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        proxyFactoryBean.setProxyInterfaces(Person.class.getInterfaces());
        proxyFactoryBean.setTarget(personTarget());
        proxyFactoryBean.setInterceptorNames("debugInterceptor","myAdvisor");
        return new ProxyFactoryBean();
    }



}
